<template>
  <div class="common-header-container">
    <!-- 固定头部 -->
    <div class="common-header">
      <!-- 左侧区域 -->
      <div class="header-left" @click="handleClickLeft">
        <slot name="left"> </slot>
      </div>

      <!-- 中间标题 -->
      <div class="header-title">
        <slot name="title">
          {{ title }}
        </slot>
      </div>

      <!-- 右侧区域 -->
      <div class="header-right">
        <slot name="right"></slot>
      </div>
    </div>

    <!-- ⬇️ 占位盒子：和头部一样高，防止内容被遮挡 -->
    <div class="header-placeholder"></div>
  </div>
</template>

<script>
export default {
  name: 'CommonHeader',
  components: {},
  props: {
    title: {
      type: String,
      default: '',
    },
  },
  methods: {
    handleClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped>
/* 固定头部 */
.common-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  background-color: #ff6140;
  color: white;
  font-size: 16px;
  padding: 0 16px;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
}

.header-left {
  font-size: 16px;
  cursor: pointer;
}

.search-input {
  width: 240px;
  height: 30px;
  border-radius: 4px;
  background-color: #fff;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding-left: 8px;
  margin-left: 10px;
}

input {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 4px;
  outline: none;
}

.search-input:focus {
  border: 1px solid #007bff;
}

.header-title {
  text-align: center;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* 👇 占位盒子：和头部一样高，撑起空间 */
.header-placeholder {
  height: 46px;
  /* 必须和 .common-header 高度一致 */
  width: 100%;
}
</style>
